package com.enzoism.springboot.dive.sse.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

@Service
@Slf4j
public class DeepSeekService {

    /**
     * 模拟大模型的聊天内容
     */
    public void streamChatResponse(String message, SseEmitter emitter) {
        log.info("用户的请求的问题：{}", message);
        // 调用DeepSeek的API并流式输出
        try {
            // 模拟流式输出
            String[] responses = {"Hello! ", "How can I help you? ", "I'm an AI assistant."};
            for (String response : responses) {
                emitter.send(SseEmitter.event().data(response));
                Thread.sleep(1000); // 模拟延迟
            }
        } catch (Exception e) {
            emitter.completeWithError(e);
        }
    }
}